class WechatShareService {
  /**
   * PC端微信分享 - 简化版本
   */
  shareToWechat(shareData) {
    // 直接复制分享内容
    return this.copyShareContent(shareData)
  }

  /**
   * 复制分享内容
   */
  async copyShareContent(shareData) {
    const shareText = `${shareData.title}\n${shareData.desc}\n${shareData.link}`
    
    try {
      if (navigator.clipboard) {
        await navigator.clipboard.writeText(shareText)
        return {
          success: true,
          message: '分享内容已复制到剪贴板，请粘贴到微信分享'
        }
      } else {
        // 降级处理
        const textArea = document.createElement('textarea')
        textArea.value = shareText
        document.body.appendChild(textArea)
        textArea.select()
        document.execCommand('copy')
        document.body.removeChild(textArea)
        
        return {
          success: true,
          message: '分享内容已复制到剪贴板，请粘贴到微信分享'
        }
      }
    } catch (error) {
      return {
        success: false,
        message: '复制失败，请手动复制：' + shareText
      }
    }
  }

  /**
   * 显示分享提示
   */
  showShareTip(shareData) {
    const shareText = `${shareData.title}\n${shareData.desc}\n${shareData.link}`
    
    // 创建提示框
    const tip = document.createElement('div')
    tip.className = 'share-tip'
    tip.innerHTML = `
      <div class="tip-content">
        <h4>微信分享</h4>
        <p>请复制以下内容到微信分享：</p>
        <textarea readonly>${shareText}</textarea>
        <div class="tip-actions">
          <button onclick="navigator.clipboard.writeText('${shareText}')" class="btn-copy">复制内容</button>
          <button onclick="this.parentElement.parentElement.parentElement.remove()" class="btn-close">关闭</button>
        </div>
      </div>
    `
    
    // 添加样式
    const style = document.createElement('style')
    style.textContent = `
      .share-tip {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        display: flex;
        align-items: center;
        justify-content: center;
        z-index: 10000;
      }
      .share-tip .tip-content {
        background: white;
        border-radius: 12px;
        padding: 20px;
        max-width: 500px;
        width: 90%;
      }
      .share-tip textarea {
        width: 100%;
        height: 100px;
        margin: 10px 0;
        padding: 10px;
        border: 1px solid #ddd;
        border-radius: 6px;
        resize: none;
      }
      .share-tip .tip-actions {
        display: flex;
        gap: 10px;
        justify-content: flex-end;
      }
      .share-tip .btn-copy,
      .share-tip .btn-close {
        padding: 8px 16px;
        border: none;
        border-radius: 6px;
        cursor: pointer;
      }
      .share-tip .btn-copy {
        background: #007bff;
        color: white;
      }
      .share-tip .btn-close {
        background: #6c757d;
        color: white;
      }
    `
    
    document.head.appendChild(style)
    document.body.appendChild(tip)
    
    // 点击背景关闭
    tip.addEventListener('click', (e) => {
      if (e.target === tip) {
        tip.remove()
      }
    })
  }
}

export default new WechatShareService()



